import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import VueRouter from 'vue-router' //引入路由依赖
import Hello from "./components/Hello";
import Login from "./components/Login";
import axios from "axios";
import List from "./components/List";
Vue.prototype.$http=axios;
const router=new VueRouter({
  routes:[
    {path:"/index",
      component: Hello
    },
    {path:"/login",
      component: Login
    },
    {path:"/",redirect:"/login"},
    {path:"/list",component:List}
  ]
});

router.beforeEach((to,from,next)=>{
  if(to.path != '/login'){
    let token=window.localStorage.getItem("token");
    console.log("token",token);
    if(token == null || token == '' || token === undefined){
      next("/login");
    }else{
      console.log("进入else");
      next();
    }
  }else{
    console.log(to.path);
    next();
  }
});

Vue.use(ElementUI)
//安装路由
Vue.use(VueRouter)
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
